home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Drivers / FastPAR1_0.lha / Source / FastPAR.c next >
Encoding:
C/C++ Source or Header  |  1993-09-13  |  7.9 KB  |  185 lines

  1. #ifndef EXEC_EXECBASE_H
  2. #include <exec/execbase.h>
  3. #endif
  4.  
  5. #ifndef EXEC_ALERTS_H
  6. #include <exec/alerts.h>
  7. #endif
  8.  
  9. #ifndef RESOURCES_MISC_H
  10. #include <resources/misc.h>
  11. #endif
  12.  
  13. #ifndef HARDWARE_CIA_H
  14. #include <hardware/cia.h>
  15. #endif
  16.  
  17. #ifndef DOS_FILEHANDLER_H
  18. #include <dos/filehandler.h>
  19. #endif
  20.  
  21. #ifndef CLIB_EXEC_PROTOS_H
  22. #include <clib/exec_protos.h>
  23. #endif
  24.  
  25. #ifndef CLIB_DOS_PROTOS_H
  26. #include <clib/dos_protos.h>
  27. #endif
  28.  
  29. #ifndef CLIB_MISC_PROTOS_H
  30. #include <clib/misc_protos.h>
  31. #endif
  32.  
  33. #include <pragmas/exec_pragmas.h>
  34. #include <pragmas/dos_pragmas.h>
  35. #include <pragmas/misc_pragmas.h>
  36.  
  37. /***********************************************/
  38.  
  39. struct Interrupt *CIAA_AddICRVector(long, struct Interrupt *);
  40. void CIAA_RemICRVector(long, struct Interrupt *);
  41. WORD CIAA_AbleICR(long);
  42. WORD CIAA_SetICR(long);
  43.  
  44. #pragma libcall CIAABase CIAA_AddICRVector 6 9002
  45. #pragma libcall CIAABase CIAA_RemICRVector C 9002
  46. #pragma libcall CIAABase CIAA_AbleICR 12 001
  47. #pragma libcall CIAABase CIAA_SetICR 18 001
  48.  
  49. extern struct CIA volatile __far ciaa;
  50. extern struct CIA volatile __far ciab;
  51.  
  52. /***********************************************/
  53.  
  54. void DummyInterrupt(void) {}   /* Just in case... */
  55.  
  56. /***********************************************/
  57.  
  58. void __saveds FastPAR(void)
  59.  
  60. {
  61.    struct ExecBase *SysBase;
  62.    struct DosLibrary *DOSBase;
  63.    struct DosPacket *Packet;
  64.    struct DeviceNode *DeviceNode;
  65.    APTR MiscBase;
  66.    APTR CIAABase;
  67.    struct Process *MyProcess;
  68.    struct Interrupt CIAAInterrupt;
  69.    WORD OldMask;
  70.  
  71.    SysBase=(struct ExecBase *)*(ULONG *)4;
  72.    if (!(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)))
  73.       {
  74.          Alert(AT_DeadEnd | AG_OpenLib | AO_DOSLib);
  75.       }
  76.    MyProcess=(struct Process *)(SysBase->ThisTask);
  77.  
  78.    Packet=WaitPkt();
  79.    DeviceNode=BADDR(Packet->dp_Arg3);
  80.    DeviceNode->dn_Task=&MyProcess->pr_MsgPort;
  81.    ReplyPkt(Packet,DOSTRUE,0L);
  82.  
  83.    MiscBase=NULL;
  84.    CIAAInterrupt.is_Node.ln_Type=NT_UNKNOWN;
  85.    CIAAInterrupt.is_Node.ln_Name="FastPAR";
  86.    CIAAInterrupt.is_Code=DummyInterrupt;
  87.    while (TRUE)
  88.       {
  89.          Packet=WaitPkt();
  90.          switch(Packet->dp_Type)
  91.             {
  92.                case ACTION_FINDINPUT:
  93.                case ACTION_FINDOUTPUT:
  94.                case ACTION_FINDUPDATE:      if (MiscBase)
  95.                                                {
  96.                                                   ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  97.                                                   break;
  98.                                                }
  99.                                             if (!(MiscBase=OpenResource("misc.resource")))
  100.                                                {
  101.                                                   Alert(AT_DeadEnd | AG_OpenRes | AO_MiscRsrc);
  102.                                                }
  103.                                             if (AllocMiscResource(MR_PARALLELPORT,"FastPAR"))
  104.                                                {
  105.                                                   MiscBase=NULL;
  106.                                                   ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  107.                                                   break;
  108.                                                }
  109.                                             if (AllocMiscResource(MR_PARALLELBITS,"FastPAR"))
  110.                                                {
  111.                                                   FreeMiscResource(MR_PARALLELPORT);
  112.                                                   MiscBase=NULL;
  113.                                                   ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  114.                                                   break;
  115.                                                }
  116.                                             if (!(CIAABase=OpenResource("ciaa.resource")))
  117.                                                {
  118.                                                   Alert(AT_DeadEnd | AG_OpenRes | AO_CIARsrc);
  119.                                                }
  120.                                             Disable();
  121.                                             if (CIAA_AddICRVector(CIAICRB_FLG,&CIAAInterrupt))
  122.                                                {
  123.                                                   Enable();
  124.                                                   MiscBase=NULL;
  125.                                                   ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  126.                                                   break;
  127.                                                }
  128.                                             CIAA_SetICR(CIAICRF_FLG);
  129.                                             OldMask=CIAA_AbleICR(CIAICRF_FLG) & CIAICRF_FLG;
  130.                                             Enable();
  131.                                             ciaa.ciaddrb=0xff;
  132.                                             ciab.ciaddra&=~(CIAF_PRTRSEL | CIAF_PRTRPOUT | CIAF_PRTRBUSY);
  133.                                             ReplyPkt(Packet,DOSTRUE,0L);
  134.                                             break;
  135.  
  136.                case ACTION_WRITE:           {
  137.                                                long Count;
  138.                                                char *CharPointer;
  139.                                                BYTE OldTaskPri;
  140.  
  141.                                                CharPointer=(char *)Packet->dp_Arg2;
  142.                                                OldTaskPri=SetTaskPri(MyProcess,-5);
  143.                                                for (Count=0; Count<Packet->dp_Arg3; Count++)
  144.                                                   {
  145.                                                      while (ciab.ciapra & CIAF_PRTRBUSY) ;
  146.                                                      ciaa.ciaprb=*CharPointer++;
  147.                                                      while (!(CIAA_SetICR(CIAICRF_FLG) & CIAICRF_FLG)) ;
  148.                                                   }
  149.                                                SetTaskPri(MyProcess,OldTaskPri);
  150.                                                ReplyPkt(Packet,Count,0L);
  151.                                             }
  152.                                             break;
  153.  
  154.                case ACTION_END:             CIAA_SetICR(CIAICRF_SETCLR | OldMask);
  155.                                             CIAA_AbleICR(CIAICRF_SETCLR | OldMask);
  156.                                             CIAA_RemICRVector(CIAICRB_FLG,&CIAAInterrupt);
  157.                                             FreeMiscResource(MR_PARALLELBITS);
  158.                                             FreeMiscResource(MR_PARALLELPORT);
  159.                                             MiscBase=NULL;
  160.                                             ReplyPkt(Packet,DOSTRUE,0L);
  161.                                             break;
  162.  
  163.                case ACTION_DIE:             if (!MiscBase)
  164.                                                {
  165.                                                   Forbid();
  166.                                                   if (IsMsgPortEmpty(&MyProcess->pr_MsgPort))
  167.                                                      {
  168.                                                         ReplyPkt(Packet,DOSTRUE,0L);
  169.                                                         UnLoadSeg(DeviceNode->dn_SegList);
  170.                                                         DeviceNode->dn_SegList=NULL;
  171.                                                         DeviceNode->dn_Task=NULL;
  172.                                                         CloseLibrary((struct Library *)DOSBase);
  173.                                                         return;
  174.                                                      }
  175.                                                   Permit();
  176.                                                }
  177.                                             ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  178.                                             break;
  179.  
  180.                default:                     ReplyPkt(Packet,DOSFALSE,ERROR_ACTION_NOT_KNOWN);
  181.                                             break;
  182.             }
  183.       }
  184. }
  185.